package com.cenntro.nearr.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@Configuration
public class CustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {

	
	@Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

	
	@Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myInterceptor()).addPathPatterns("/**/**").excludePathPatterns("/**/login").excludePathPatterns("/**/loginout");  //对来自/user/** 这个链接来的请求进行拦截
        
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		String os = System.getProperty("os.name").toLowerCase();
		if (os.toLowerCase().indexOf("window") >= 0){
			registry.addResourceHandler("/upload/**").addResourceLocations("file:///opt/data/upload/");  
		}else {
			registry.addResourceHandler("/upload/**").addResourceLocations("file:///opt/data/upload/");
		}
		
	}
}
